package org.springblade.modules.digitalization.wrapper;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import lombok.Data;
import org.springblade.core.tool.utils.Func;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserMenuRs {

	@JacksonXmlProperty(localName = "类号")
	private String classNum;


	@JacksonXmlProperty(localName = "序号")
	private String idNum;

	@JacksonXmlProperty(localName = "材料名称")
	private String caiLiaoName;

	@JsonIgnore
	private Date createAt;

	@JacksonXmlProperty(localName = "材料形成时间")
	private String createAtStr;

	@JacksonXmlProperty(localName = "备注")
	private String remark;


	@JsonSerialize(using = MyIntegerToStringSerializer.class)
	@JacksonXmlProperty(localName = "页数")
	private Integer pageNum;

	@JacksonXmlElementWrapper(useWrapping = false)
	@JacksonXmlProperty(localName = "原始图像数据_Text")
	private List<String> orgImgs = new ArrayList<>();

	@JacksonXmlElementWrapper(useWrapping = false)
	@JacksonXmlProperty(localName = "优化图像数据_Text")
	private List<String> hdImgs = new ArrayList<>();

	@JsonIgnore
	private String tmpOrg;

	@JsonIgnore
	private String tmpHd;

	@JsonIgnore
	private String year;

	@JsonIgnore
	private String month;

	@JsonIgnore
	private String day;

}

class MyIntegerToStringSerializer extends JsonSerializer<Integer> {
	@Override
	public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		gen.writeString(value.toString());
	}
}


class MyDateSerializer extends JsonSerializer<Date> {
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

	@Override
	public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		if (!Func.isEmpty(value)) {
			String formattedDate = dateFormat.format(value);
			gen.writeString(formattedDate);
		}
	}
}
